/*****************************************************************************
 
 File:   OTKWorkspaceManager.java
 
 Date          Build     Author        Version    Comments
29-May-12    P-20-54    rkothari          $$1        Created

****************************************************************************/
package com.ptc.otkjavaexamples.ui;

import com.ptc.cipjava.jxthrowable;
import com.ptc.cipjava.stringseq;
import com.ptc.uifc.uifcCore.FontStyle;
import com.ptc.uifc.uifcCore.RowPositionData;
import com.ptc.uifc.uifcCore.uifcCore;
import com.ptc.uifc.uifcLabel.Label;
import com.ptc.uifc.uifcLabel.uifcLabel;
import com.ptc.uifc.uifcTable.DefaultTableListener;
import com.ptc.uifc.uifcTable.Table;
import com.ptc.uifc.uifcTable.TableCell;
import com.ptc.uifc.uifcTable.TableRow;
import com.ptc.uifc.uifcTable.uifcTable;
/*
 * Listener class for  Server Table 
 */
public class OTKWorkspaceManager extends DefaultTableListener
{
    private Table workspaceTable;
    
    OTKWorkspaceManager()
    {			
	try
	    {
		workspaceTable = uifcTable.TableFind(OTKServerRegistryDialog.OTK_SERVER_DIALOG,OTKServerRegistryDialog.OTK_WS_TABLE);
		workspaceTable.SetFontStyle(FontStyle.FONT_STYLE_BOLD);
		workspaceTable.SetFontSize(10);
		
		TableRow row = uifcTable.TableRowDefine("workspace_row");
		RowPositionData rowPos = uifcCore.RowPositionData_Create();
		rowPos.SetIndex(-1);				 
		workspaceTable.InsertRow(row, rowPos);			 
		
	    } 
	catch (jxthrowable e)
	    {			
		e.printStackTrace();
	    }
	
    }		
    
    /*		 
     * Override method OnCellSelect to handle event of selecting a cell of Server Table
     * On each selection in server table fill workspace table with workspace name and context
     * On each selection in server table fill information of server name and location in Description layout
     */
    @Override
	public void OnCellSelect(Table handle) throws jxthrowable
    {
	try
	    {
		stringseq selNames = handle.GetSelectedCellNameArray();		  
		
		TableCell wsCell =  uifcTable.TableCellFind(workspaceTable.GetDialog(), workspaceTable.GetComponent(),"workspace_row", "workspace");
		wsCell.SetText(selNames.get(0) + " Active WorkSpace");
		
		TableCell contextCell =  uifcTable.TableCellFind(workspaceTable.GetDialog(), workspaceTable.GetComponent(),"workspace_row", "context");
		contextCell.SetText("Windchill PDM");
		
		Label serverName = uifcLabel.LabelFind(OTKServerRegistryDialog.OTK_SERVER_DIALOG, "server_name_lb");
		serverName.SetText("Server Name : " + selNames.get(0));
		
		Label serverLoc = uifcLabel.LabelFind(OTKServerRegistryDialog.OTK_SERVER_DIALOG, "location_lb");
		serverLoc.SetText("Location : https\\\\ " + selNames.get(0) + ": 8080");
		
		Label wsName = uifcLabel.LabelFind(OTKServerRegistryDialog.OTK_SERVER_DIALOG, "workspace_lb");
		wsName.SetText("Workspace Name : " + selNames.get(0) + " Active WorkSpace");
		
	    }
	catch (jxthrowable e)
	    {			
		e.printStackTrace();
	    }
	
	
    }	
    
    
}
